<?php
class CountryModel extends Models
{
    public $id, $name, $code2, $code3, $addressFormat, $postcodeReq, $status;
    protected $attributes;
	protected $tableName='country';

    public function getAll()
    {
        if(!$countries=$this->findAllModes($this->tableName)) return false;

        $result=array();
        foreach($countries as $country){
            if($country){
                $this->id               =$country['country_id'];
                $this->name             =$country['name'];
                $this->code2            =$country['iso_code_2'];
                $this->code3            =$country['iso_code_3'];
                $this->addressFormat    =$country['address_format'];
                $this->postcodeReq      =$country['postcode_required'];
                $this->status           =$country['status'];

                $result[]=$this;
            }
        }

        return $result;
    }

    public function findByPk($id)
    {
        if(!$country=$this->findModelByPk($id, $this->tableName)) return false;

        $this->id               =$country['country_id'];
        $this->name             =$country['name'];
        $this->code2            =$country['iso_code_2'];
        $this->code3            =$country['iso_code_3'];
        $this->addressFormat    =$country['address_format'];
        $this->postcodeReq      =$country['postcode_required'];
        $this->status           =$country['status'];

        return $this;
    }

    public function findByAttributes($attributes=array())
    {
        if(!$attributes) return null;
        if(!$countries=$this->findModelsByAttributes($attributes, $this->tableName)) return false;

        $result=array();
        foreach($countries as $country){
            if($country){
                $this->id               =$country['country_id'];
                $this->name             =$country['name'];
                $this->code2            =$country['iso_code_2'];
                $this->code3            =$country['iso_code_3'];
                $this->addressFormat    =$country['address_format'];
                $this->postcodeReq      =$country['postcode_required'];
                $this->status           =$country['status'];

                $result[]=$this;
            }
        }

        return $result;
    }

    public function update($id, $attributes)
    {
        return $this->updateModel($id, $this->tableName, $attributes);
    }

    public function getTableName(){
        return $this->tableName;
    }
}